package com.sergiandreplace.kaboom.browser;

import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.sergiandreplace.kaboom.R;
import com.sergiandreplace.kaboom.comic.Comic;
import com.sergiandreplace.kaboom.comic.Comic.OnPageLoadedListener;

public class FileIcon implements Comparable<FileIcon>, OnPageLoadedListener
{

	private String name = "";
	private FileType type = null;
	private Bitmap thumbnail = null;
	private Comic comic = null;
	private View iconView = null;

	
	
	public String getName()
	{
		return this.name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public FileType getType()
	{
		return this.type;
	}

	public void setType(FileType type)
	{
		this.type = type;
	}

	@Override
	public int compareTo(FileIcon another)
	{
		if (this.type.getOrder() < another.getType().getOrder())
			return -1;
		else if (this.type.getOrder() > another.getType().getOrder())
			return 1;
		else
			return this.getName().compareToIgnoreCase(another.getName());

	}

	public void setThumbnail(Bitmap thumbnail)
	{
		this.thumbnail = thumbnail;
	}

	public Bitmap getThumbnail()
	{
		return thumbnail;
	}

	public void setComic(Comic comic)
	{
		this.comic = comic;
		this.comic.setOnPageLoadedListener(this);
	}

	public Comic getComic()
	{
		return comic;
	}

	@Override
	public void onBitmapLoaded(Bitmap thumb)
	{
		this.thumbnail = thumb;
		if (this.iconView != null)
		{
			ImageView thumbView = (ImageView) iconView.findViewById(R.id.comicIcon);
			thumbView.setImageBitmap(thumbnail);
			thumbView.setVisibility(View.VISIBLE);
			((ProgressBar) iconView.findViewById(R.id.fileProgress)).setVisibility(View.INVISIBLE);
		}

	}

	public void setIconView(View iconView)
	{
		this.iconView = iconView;
	}

	public View getIconView()
	{
		return iconView;
	}

}
